package com.jack.helloworld.activity;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.jack.helloworld.R;
import com.jack.helloworld.fragment.ToFFragment;

import androidx.appcompat.app.AppCompatActivity;

public class FragmentReceiveActivity extends AppCompatActivity {

    EditText editTextFragment;
    Button btnSentToFragment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_receive);

        initView();
        initData();
    }

    private void initView() {
        editTextFragment = (EditText) findViewById(R.id.editTextFragment);
        btnSentToFragment = (Button) findViewById(R.id.btnSentToFragment);
    }

    private void initData() {

        btnSentToFragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = editTextFragment.getText().toString();
                Bundle bundle = new Bundle();
                bundle.putString("inputString", text);

                Fragment fragment = new ToFFragment();
                fragment.setArguments(bundle);

                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.add(R.id.activity_fragment_receive, fragment, "fragmentReceive");
                fragmentTransaction.commit();

            }
        });
    }
}
